class Solution:
    def getLucky(self, s: str, k: int) -> int:
        def toSum(num: int):
            x = 0
            while num > 0:
                div, mod = divmod(num, 10)
                num = div
                x += mod
            return x

        num = 0
        for string in s:
            n = ord(string) - ord('a') + 1
            if n >= 10:
                num *= 100
            else:
                num *= 10
            num += n

        for i in range(k):
            num = toSum(num)
        return num
